package org.sergiy.forecast;

import java.io.Serializable;
import java.net.URL;
import java.util.Date;

/**
 * Forecast 
 * 
 * @author Sergiy Litsenko
 *
 */
public class Forecast implements Serializable {
	private static final long serialVersionUID = 360510681383034563L;
	// suburb, city, state
	private String locationName;
	// start date of forecast
	private Date startDate;
	// end date of forecast
	private Date endDate;
	// forecast detailed description
	private String forecastDetailedDescription;
	// forecast brief description
	private String forecastBriefDescription;
	// forecast icon code
	private Integer iconCode;
	// forecast icon image URL as string
	private String image;
	// precipitation probability %
	private Integer precipitationProbability;
	// precipitation range, mm, min-max 
	private String precipitationRange;
	// air temperature minimum, Celsius 
	private Integer airTemperatureMinimum;
	// air temperature maximum, Celsius 
	private Integer airTemperatureMaximum;
	// UV alert
	private String uvAlert;
	// fire alert
	private String fireAlert;
	
	/**
	 * Default constructor
	 */
	public Forecast() {
	}

	/**
	 * Constructor
	 * 
	 * @param locationName the suburb, city, state
	 * @param startDate start date of forecast
	 * @param endDate end date of forecast
	 * @param forecastBriefDescription forecast brief description
	 * @param forecastDetailedDescription forecast detailed description
	 * @param airTemperatureMinimum air temperature minimum, Celsius 
	 * @param airTemperatureMaximum air temperature maximum, Celsius 
	 * @param iconCode forecast icon code
	 * @param precipitationProbability precipitation probability %
	 * @param precipitationRange precipitation range, mm, min - max
	 * @param uvAlert UV alert 
	 * @param fireAlert fire alert
	 */
	public Forecast(
			String locationName, 
			Date startDate, 
			Date endDate,
			String forecastBriefDescription,
			String forecastDetailedDescription, 
			Integer airTemperatureMinimum,
			Integer airTemperatureMaximum, 
			Integer iconCode,
			String image,
			Integer precipitationProbability, 
			String precipitationRange,
			String uvAlert,
			String fireAlert) {
		
		super();
		this.locationName = locationName;
		this.startDate = startDate;
		this.endDate = endDate;
		this.forecastBriefDescription = forecastBriefDescription;
		this.forecastDetailedDescription = forecastDetailedDescription;
		this.airTemperatureMinimum = airTemperatureMinimum;
		this.airTemperatureMaximum = airTemperatureMaximum;
		this.iconCode = iconCode;
		this.image = image;
		this.precipitationProbability = precipitationProbability;
		this.precipitationRange = precipitationRange;
		this.uvAlert = uvAlert;
		this.fireAlert = fireAlert;
	}

	/**
	 * @return the locationName
	 */
	public String getLocationName() {
		return locationName;
	}

	/**
	 * @param locationName the locationName to set
	 */
	public void setLocationName(String locationName) {
		this.locationName = locationName;
	}

	/**
	 * @return the startDate
	 */
	public Date getStartDate() {
		return startDate;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * @return the forecastDetailedDescription
	 */
	public String getForecastDetailedDescription() {
		return forecastDetailedDescription;
	}

	/**
	 * @param forecastDetailedDescription the forecastDetailedDescription to set
	 */
	public void setForecastDetailedDescription(String forecastDetailedDescription) {
		this.forecastDetailedDescription = forecastDetailedDescription;
	}

	/**
	 * @return the forecastBriefDescription
	 */
	public String getForecastBriefDescription() {
		return forecastBriefDescription;
	}

	/**
	 * @param forecastBriefDescription the forecastBriefDescription to set
	 */
	public void setForecastBriefDescription(String forecastBriefDescription) {
		this.forecastBriefDescription = forecastBriefDescription;
	}

	/**
	 * @return the iconCode
	 */
	public Integer getIconCode() {
		return iconCode;
	}

	/**
	 * @param iconCode the iconCode to set
	 */
	public void setIconCode(Integer iconCode) {
		this.iconCode = iconCode;
	}

	/**
	 * @return the precipitationProbability
	 */
	public Integer getPrecipitationProbability() {
		return precipitationProbability;
	}

	/**
	 * @param precipitationProbability the precipitationProbability to set
	 */
	public void setPrecipitationProbability(Integer precipitationProbability) {
		this.precipitationProbability = precipitationProbability;
	}

	/**
	 * @return the precipitationRange
	 */
	public String getPrecipitationRange() {
		return precipitationRange;
	}

	/**
	 * @param precipitationRange the precipitationRange to set
	 */
	public void setPrecipitationRange(String precipitationRange) {
		this.precipitationRange = precipitationRange;
	}

	/**
	 * @return the airTemperatureMinimum
	 */
	public Integer getAirTemperatureMinimum() {
		return airTemperatureMinimum;
	}

	/**
	 * @param airTemperatureMinimum the airTemperatureMinimum to set
	 */
	public void setAirTemperatureMinimum(Integer airTemperatureMinimum) {
		this.airTemperatureMinimum = airTemperatureMinimum;
	}

	/**
	 * @return the airTemperatureMaximum
	 */
	public Integer getAirTemperatureMaximum() {
		return airTemperatureMaximum;
	}

	/**
	 * @param airTemperatureMaximum the airTemperatureMaximum to set
	 */
	public void setAirTemperatureMaximum(Integer airTemperatureMaximum) {
		this.airTemperatureMaximum = airTemperatureMaximum;
	}

	/**
	 * @return the image
	 */
	public String getImage() {
		return image;
	}

	/**
	 * @param image the image to set
	 */
	public void setImage(String image) {
		this.image = image;
	}

	/**
	 * @return the uvAlert
	 */
	public String getUvAlert() {
		return uvAlert;
	}

	/**
	 * @param uvAlert the uvAlert to set
	 */
	public void setUvAlert(String uvAlert) {
		this.uvAlert = uvAlert;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return String.format(
				"Forecast [locationName=%s, startDate=%s, endDate=%s, forecastBriefDescription=%s, forecastDetailedDescription=%s, iconCode=%s, image=%s, precipitationProbability=%s, precipitationRange=%s, airTemperatureMinimum=%s, airTemperatureMaximum=%s, uvAlert=%s, fireAlert=%s]",
				locationName, startDate, endDate,
				forecastBriefDescription, forecastDetailedDescription,
				iconCode, image, precipitationProbability,
				precipitationRange, airTemperatureMinimum,
				airTemperatureMaximum, uvAlert, fireAlert);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((airTemperatureMaximum == null) ? 0 : airTemperatureMaximum
						.hashCode());
		result = prime
				* result
				+ ((airTemperatureMinimum == null) ? 0 : airTemperatureMinimum
						.hashCode());
		result = prime * result + ((endDate == null) ? 0 : endDate.hashCode());
		result = prime * result
				+ ((fireAlert == null) ? 0 : fireAlert.hashCode());
		result = prime
				* result
				+ ((forecastBriefDescription == null) ? 0
						: forecastBriefDescription.hashCode());
		result = prime
				* result
				+ ((forecastDetailedDescription == null) ? 0
						: forecastDetailedDescription.hashCode());
		result = prime * result
				+ ((iconCode == null) ? 0 : iconCode.hashCode());
		result = prime * result + ((image == null) ? 0 : image.hashCode());
		result = prime * result
				+ ((locationName == null) ? 0 : locationName.hashCode());
		result = prime
				* result
				+ ((precipitationProbability == null) ? 0
						: precipitationProbability.hashCode());
		result = prime
				* result
				+ ((precipitationRange == null) ? 0 : precipitationRange
						.hashCode());
		result = prime * result
				+ ((startDate == null) ? 0 : startDate.hashCode());
		result = prime * result + ((uvAlert == null) ? 0 : uvAlert.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Forecast)) {
			return false;
		}
		Forecast other = (Forecast) obj;
		if (airTemperatureMaximum == null) {
			if (other.airTemperatureMaximum != null) {
				return false;
			}
		} else if (!airTemperatureMaximum.equals(other.airTemperatureMaximum)) {
			return false;
		}
		if (airTemperatureMinimum == null) {
			if (other.airTemperatureMinimum != null) {
				return false;
			}
		} else if (!airTemperatureMinimum.equals(other.airTemperatureMinimum)) {
			return false;
		}
		if (endDate == null) {
			if (other.endDate != null) {
				return false;
			}
		} else if (!endDate.equals(other.endDate)) {
			return false;
		}
		if (fireAlert == null) {
			if (other.fireAlert != null) {
				return false;
			}
		} else if (!fireAlert.equals(other.fireAlert)) {
			return false;
		}
		if (forecastBriefDescription == null) {
			if (other.forecastBriefDescription != null) {
				return false;
			}
		} else if (!forecastBriefDescription
				.equals(other.forecastBriefDescription)) {
			return false;
		}
		if (forecastDetailedDescription == null) {
			if (other.forecastDetailedDescription != null) {
				return false;
			}
		} else if (!forecastDetailedDescription
				.equals(other.forecastDetailedDescription)) {
			return false;
		}
		if (iconCode == null) {
			if (other.iconCode != null) {
				return false;
			}
		} else if (!iconCode.equals(other.iconCode)) {
			return false;
		}
		if (image == null) {
			if (other.image != null) {
				return false;
			}
		} else if (!image.equals(other.image)) {
			return false;
		}
		if (locationName == null) {
			if (other.locationName != null) {
				return false;
			}
		} else if (!locationName.equals(other.locationName)) {
			return false;
		}
		if (precipitationProbability == null) {
			if (other.precipitationProbability != null) {
				return false;
			}
		} else if (!precipitationProbability
				.equals(other.precipitationProbability)) {
			return false;
		}
		if (precipitationRange == null) {
			if (other.precipitationRange != null) {
				return false;
			}
		} else if (!precipitationRange.equals(other.precipitationRange)) {
			return false;
		}
		if (startDate == null) {
			if (other.startDate != null) {
				return false;
			}
		} else if (!startDate.equals(other.startDate)) {
			return false;
		}
		if (uvAlert == null) {
			if (other.uvAlert != null) {
				return false;
			}
		} else if (!uvAlert.equals(other.uvAlert)) {
			return false;
		}
		return true;
	}

	/**
	 * @return the fireAlert
	 */
	public String getFireAlert() {
		return fireAlert;
	}

	/**
	 * @param fireAlert the fireAlert to set
	 */
	public void setFireAlert(String fireAlert) {
		this.fireAlert = fireAlert;
	}

	/**
	 * Convert temperature range to string
	 * @return temperature range as string
	 */
	public String getTemperatureRangeAsString () {
		StringBuffer buffer = new StringBuffer();
		if (airTemperatureMinimum != null) {
			buffer.append (airTemperatureMinimum);
		}
		
		if (airTemperatureMaximum != null) {
			if (buffer.length()>0) {
				buffer.append (" - ");
			}
			buffer.append (airTemperatureMaximum);
		}
		
		return buffer.toString();
	}
}
